package com.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.model.Member;

public class MemberDAO extends GenericDAO<Member> {

	private static final long serialVersionUID = 1L;

	public MemberDAO() {
		super(Member.class);
	}
	
	public Member findMemberWithNRIC (String nric) {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("nric", nric);

		return super.findOneResult(Member.FIND_MEMBER_BY_NRIC, parameters);
	}
	
	public Member findActiveMemberWithName (String name) {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("name", name);
		parameters.put("active", true);
		parameters.put("suspended", false);		

		return super.findOneResult(Member.MEMBERSHIP_AUTOCOMPLETE, parameters);
	}	
	
	public List<Member> listActive () {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("active", true);
		parameters.put("suspend", false);

		return super.findManyResult(Member.FIND_MEMBER_BY_STATUS_SUSPEND, parameters);
	}
	
	public List<Member> search(Map<String, Object> parameters){
		
		return super.findManyResult(Member.ADVANCE_SEARCH, parameters);
	}
	
	public List<Member> activeMemberAutoComplete (String name){
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("name", "%"+name+"%");
		parameters.put("active", true);
		parameters.put("suspended", false);
		
		return super.findManyResult(Member.MEMBERSHIP_AUTOCOMPLETE, parameters);
		
	}	

}
